//
//  HZViewConvertImage.m
//  HZtest
//
//  Created by huazi on 14-9-22.
//  Copyright (c) 2014年 HZ. All rights reserved.
//

#import "HZViewConvertImage.h"

@implementation HZViewConvertImage
+(UIImage *)getImage:(UIView *)view
{
    
    CGSize size =CGSizeMake(view.frame.size.width, view.frame.size.height);
    UIGraphicsBeginImageContext(size);
    //获取图像
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
+(void)saveImageToPhotos:(UIImage*)savedImage AndVCtargt:(UIViewController *)VC
{
    UIImageWriteToSavedPhotosAlbum(savedImage, VC, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
}


// 指定回调方法这个方法要保存图片类的回调，记得在保存图片类的重写 
-(void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
    NSString *msg = nil ;
    if(error != NULL){
        msg = @"保存图片失败" ;
    }else{
        msg = @"保存图片成功" ;
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存图片结果提示"
                                                    message:msg
                                                   delegate:self
                                          cancelButtonTitle:@"确定"
                                          otherButtonTitles:nil];
    [alert show];
}


@end
